using System.Linq;
using NUnit.Framework;

namespace Flit.Tests
{
    [TestFixture]
    public class StateTest : ParserTestBase
    {
        [Test]
        public void HasIdentifier()
        {
            Graph node = Parse("digraph g{x y; z}");
            Assert.AreEqual("x", node.States.First().Identifier);
        }

        [Test]
        public void HasUnquotedAttributes()
        {
            Graph node = Parse("digraph g{x[foo=bar, x=y] y; z}");
            Assert.AreEqual("x", node.States.First().Identifier);
            Assert.AreEqual("bar", node.States.First().GenericAttributes["foo"]);
        }

        [Test]
        public void HasQuotedAttributes()
        {
            Graph node = Parse("digraph g{x[foobar=\"FooBar\"] y; z}");
            Assert.AreEqual("x", node.States.First().Identifier);
            Assert.AreEqual("FooBar", node.States.First().GenericAttributes["foobar"]);
        }

        [Test]
        public void WithoutParametersHasName()
        {
            Graph node = Parse("digraph g{x[label=\"FooBar\"] y; z}");
            Assert.AreEqual("x", node.States.First().Identifier);
            Assert.AreEqual("FooBar", node.States.First().Label.Name);
        }

        [Test]
        public void WithParametersHasName()
        {
            Graph node = Parse("digraph g{x[label=\"FooBar(string s, int i)\"] y; z}");
            Assert.AreEqual("x", node.States.First().Identifier);
            Assert.AreEqual("FooBar", node.States.First().Label.Name);
        }

        [Test]
        public void HasParameters()
        {
            Graph node = Parse("digraph g{x[label=\"FooBar(string s, int i)\"] y; z}");
            Assert.AreEqual("x", node.States.First().Identifier);
            Assert.AreEqual("FooBar", node.States.First().Label.Name);
            Assert.AreEqual(2, node.States.First().Label.Parameters.Count());
            Assert.AreEqual("string", node.States.First().Label.Parameters.First().DataType);
        }
    }
}